package oad.a233.v1.control;

import java.util.ArrayList;
import java.util.List;

import oad.a233.v1.entity.CapFormItem;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.MeasureSpec;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class OADCapForm_Record extends OADCapForm {

	private List<RelativeLayout> _RecordList;	
	private List<CapFormItem> _Data = null;
	private int _RecoredCount = 0;
	private int _RecoredHeight = 25;
	private LinearLayout _MainLayout;
	
	public void set_Record(List<CapFormItem> data) {
		
		_Data = data;
		_RecoredCount = _Data.size();
		_RecordList.clear();
		SetRecoredData();
	//	this.invalidate();
		
		
	}

	public OADCapForm_Record(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
		InitView();
	}

	@Override
	void capLayout(boolean c, int l, int t, int r, int b) {
		// TODO Auto-generated method stub
		b+= _MainLayout.getMeasuredHeight();
		_MainLayout.layout(l, t, r, b);	
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		// TODO Auto-generated method stub
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		
		
		_MainLayout.measure(widthMeasureSpec, heightMeasureSpec);		
		
		
	}

	
	private void InitView() {
		// TODO Auto-generated method stub
	
		
		_RecoredHeight = 25;
		
		if(_RecordList == null)  _RecordList= new ArrayList<RelativeLayout>();
		
		_MainLayout = new LinearLayout(this._Context,this._Attrs);		
		_MainLayout.setBackgroundResource(R.drawable.oad_list_cornor_round_bottom);
		_MainLayout.setOrientation(LinearLayout.VERTICAL);
		
		this.addView(_MainLayout);		
		
		this.setWillNotDraw(false);
	
	}
	
	
	private void SetRecoredData()
	{
		if(_Data !=null)
		{			
			for(int i=0;i<_RecoredCount;i++)
			{	
				RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,_RecoredHeight);
				
				
				RelativeLayout r =  (RelativeLayout) OADCapForm.inflate(_Context,R.layout.titlelv_record_opal,null);			
				r.setLayoutParams(lp);
				
				lp.setMargins(1, 1, 1, 1);
				int w = r.getWidth();
				int h = r.getHeight();
				
				TextView tv = (TextView) r.findViewById(R.id.titlelv_record_txtInfo);
				CapFormItem dItem = _Data.get(i);
				tv.setText(dItem.getInfo());
				
				_RecordList.add(r);
				_MainLayout.addView(r);				
				
				
			}
		}
	}

	@Override
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		
	//	_MainLayout.draw(canvas);
		for(int i=0;i<_MainLayout.getChildCount();i++)
		{
			View v = _MainLayout.getChildAt(i);
			v.draw(canvas);
			Paint p = new Paint();
			p.setColor(Color.parseColor("#ff0000"));
			p.setStrokeWidth(10);
			canvas.drawLine(v.getLeft(), v.getBottom(), v.getRight(), v.getBottom(), p);
		}
		
	}
	
	/*
	private void DemoData()
	{
		List<CapFormItem> list =new ArrayList<CapFormItem>();
		CapFormItem item = new CapFormItem("11");
		list.add(item);
		item = new CapFormItem("22");
		list.add(item);
		item = new CapFormItem("33");
		list.add(item);
		
		_Data = list;
		_RecoredCount = _Data.size();
	
	}*/
	
	
}
